package github.sf.fw.tools.db.catalog.doris;

import github.sf.fw.tools.db.catalog.Fragment;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhoup
 * @since 2023/7/26
 */
@Data
public class DorisDataModel implements Fragment {
    private DorisDataModelType dorisDataModelType;
    private List<String> columns;

    @Override
    public String getFragment() {
        if (DorisDataModelType.Duplicate == dorisDataModelType) {
            if (columns == null || columns.isEmpty()) {
                return "";
            }
        } else {
            if (columns == null || columns.isEmpty()) {
                throw new IllegalArgumentException("数据模型" + dorisDataModelType + "描述的列不能为空");
            }
        }
        String collected = columns.stream().collect(Collectors.joining(",", "(", ")"));
        return dorisDataModelType.name().toUpperCase() + " KEY" + collected;
    }
}

